package paper.parse;

import paper.parse.HMMatch;
import paper.parse.HMMatcher;
import paper.token.TT;

public class TitleParser extends HMMatcher {
    
    /*
     * This class is used to parse titles of papers. It specialises the
     * "Hidden Markov" Matcher by adding the list of states and arrows to
     * match titles. Use via its parse() method only.
     */


    private HMMatch s00 = addState();
    private HMMatch s00a = addState();
    private HMMatch s00b = addState();
    private HMMatch s01 = addState();
    private HMMatch s01a = addState();
    private HMMatch s01b = addState();
    private HMMatch s01c = addState();
    private HMMatch s02 = addState();
    private HMMatch s02a= addState();
    private HMMatch s02b= addState();
    private HMMatch s03 = addState();
    private HMMatch s03b= addState();
    private HMMatch s04 = addState();
    private HMMatch s04b= addState();
    private HMMatch s06 = addState();
    private HMMatch s100 = addState();

    public TitleParser() {
        s00.addOut(TT.WHERE,TT.WHERE, s100);
        s00.addOut(TT.NUMBER,TT.WHERE, s100);
        s00.addOut(TT.AFFILIATION,TT.WHERE, s100);
        s00.addOut(TT.TITLE, TT.TITLE, s01a);

        s01a.addOut(TT.AUTHOR, TT.AUTHOR, s02);
        s01a.addOut(TT.TITLE,  TT.TITLE, s01b);
        s01b.addOut(TT.AUTHOR, TT.AUTHOR, s02);
        s01b.addOut(TT.TITLE,  TT.TITLE, s01c);
        s01c.addOut(TT.AUTHOR, TT.AUTHOR, s02);

        s02.addOut(TT.AUTHOR,  TT.AUTHOR, s02);
        s02.addOut(TT.AFFILIATION, TT.AFFILIATION, s03);
        s02.addOut(TT.EMAIL,   TT.EMAIL, s04);
        s02.addTerminal();

        s03.addOut(TT.AFFILIATION,TT.AFFILIATION, s03);
        s03.addOut(TT.EMAIL,   TT.EMAIL, s03b);
        s03.addOut(TT.AUTHOR,  TT.AUTHOR, s02);
        s03.addOut(TT.TITLE,   TT.RUBBISH, s06);
        s03.addTerminal();

        s03b.addOut(TT.AUTHOR,  TT.AUTHOR, s02);
        s03b.addOut(TT.TITLE,   TT.RUBBISH, s06);
        s03b.addTerminal();

        s04.addOut(TT.AUTHOR,  TT.AUTHOR, s02);
        s04.addOut(TT.AFFILIATION, TT.AFFILIATION, s04b);
        s04.addOut(TT.TITLE,   TT.RUBBISH, s06);
        s04.addTerminal();

        s04b.addOut(TT.AFFILIATION,TT.AFFILIATION, s04b);
        s04b.addOut(TT.AUTHOR,  TT.AUTHOR, s02);
        s04b.addOut(TT.TITLE,   TT.RUBBISH, s06);
        s04b.addTerminal();

        s06.addOut(TT.TITLE,      TT.RUBBISH, s06);
        s06.addTerminal();

        s100.addOut(TT.WHERE,  TT.WHERE, s100);
        s100.addOut(TT.NUMBER, TT.WHERE, s100);
        s100.addOut(TT.AFFILIATION, TT.WHERE, s100);
        s100.addOut(TT.TITLE,  TT.TITLE, s01a);
    }
}
